﻿@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

            @include('admin.layouts.navbar')
            @include('admin.layouts.sidebar')

            <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item"><a href="{{ route('admin.games.index') }}">发布记录</a></li>
                                <li class="breadcrumb-item active" aria-current="page">编辑</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                               <div class="row">
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>服务器名称：</label>
                                            <input type="text" class="form-control" id="server_name" value="{{ $userGameDataInfo->server_name }}" maxlength="8">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>服务器IP：</label>
                                            <input type="text" class="form-control" id="server_ip" value="{{ $userGameDataInfo->server_ip }}" maxlength="8">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>登录器下载：</label>
                                            <input type="text" class="form-control" id="login_down" value="{{ $userGameDataInfo->login_down }}">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>详细版本介绍：</label>
                                            <input type="text" class="form-control" id="introduction" value="{{ $userGameDataInfo->introduction }}" maxlength="20">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-row">
                                            <div class="col-lg-8">
                                                <div class="form-group">
                                                    <label>推荐星级：</label>
                                                    <input type="text" class="form-control" id="stars" value="{{ $userGameDataInfo->stars }}" >
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="form-group">
                                                    <label>发布数量：</label>
                                                    <input type="text" class="form-control" id="count" value="{{ $userGameDataInfo->count }}" onkeyup="total()">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>福利：</label>
                                            <input type="text" class="form-control" id="money" value="{{ $userGameDataInfo->money }}">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>游戏主页：
                                                <small class="text-danger">（ 注意：主页必须以http:// 或 https:// 开头 ）</small>
                                            </label>
                                            <input type="url" class="form-control" id="url" value="{{ $userGameDataInfo->url }}" maxlength="50">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <label>开机时间：</label>
                                        <div class="form-row">
                                            <div class="col">
                                                <div class="form-group">
                                                    <select class="form-control" id="is_every_day">
                                                        <option value="2" @if ($userGameDataInfo->is_every_day == 2) selected @endif>非每天</option>
                                                        <option value="1" @if ($userGameDataInfo->is_every_day == 1) selected @endif>每天</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col">
                                                <div class="form-group">
                                                    <input type="date" class="form-control" id="date" value="{{ date('Y-m-d',strtotime($userGameDataInfo->open_time)) }}" placeholder="年/月/日">
                                                </div>
                                            </div>
                                            <div class="col">
                                                <div class="form-group">
                                                    <select class="form-control" id="hour" data-hour="{{ date('H',strtotime($userGameDataInfo->open_time)) }}">
                                                        <option value=""> 请选择时</option>
                                                        <option value="00">00</option>
                                                        <option value="07">07</option>
                                                        <option value="08">08</option>
                                                        <option value="09">09</option>
                                                        <option value="10">10</option>
                                                        <option value="11">11</option>
                                                        <option value="12">12</option>
                                                        <option value="13">13</option>
                                                        <option value="14">14</option>
                                                        <option value="15">15</option>
                                                        <option value="16">16</option>
                                                        <option value="17">17</option>
                                                        <option value="18">18</option>
                                                        <option value="19">19</option>
                                                        <option value="20">20</option>
                                                        <option value="21">21</option>
                                                        <option value="22">22</option>
                                                        <option value="23">23</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col">
                                                <div class="form-group">
                                                    <select class="form-control" id="minute" data-minute="{{ date('i',strtotime($userGameDataInfo->open_time)) }}">
                                                        <option value=""> 请选择分钟</option>
                                                        <option value="00">00</option>
                                                        <option value="05">05</option>
                                                        <option value="30">30</option>
                                                        <option value="59">全天</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col">
                                                <div class="form-group">
                                                    <select class="form-control" id="is_all_day">
                                                        <option value="2" @if ($userGameDataInfo->is_all_day == 2) selected @endif>非全天</option>
                                                        <option value="1" @if ($userGameDataInfo->is_all_day == 1) selected @endif>全天</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>位置选择：</label>
                                            <select class="form-control" name="is_top" id="is_top">
                                                <option value="0" @if ($userGameDataInfo->is_top == 0) selected @endif>开服列表</option>
                                                <option value="-1" @if ($userGameDataInfo->is_top == -1) selected @endif>福利列表</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>封面图片：</label>
                                            <input type="file" class="form-control" id="image" onchange="upload_image()">
                                            <input type="hidden" id="image-value" value="{{$userGameDataInfo->image}}">
                                            @if ($userGameDataInfo->image)
                                                <a href="/uploads/{{$userGameDataInfo->image}}" id="show-image" target="_blank">查看图片</a>
                                            @endif
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>是否通区：
                                            </label>
                                            <select class="form-control" id="is_tq">
                                                <option value="2" @if ($userGameDataInfo->is_tq == 2) selected @endif>否</option>
                                                <option value="1" @if ($userGameDataInfo->is_tq == 1) selected @endif>是</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>在线客服：
                                            </label>
                                            <input type="url" class="form-control" id="kf_url" value="{{ $userGameDataInfo->kf_url }}" maxlength="50">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>是否热门：
                                            </label>
                                            <select class="form-control" id="is_rm">
                                                <option value="-1" @if ($userGameDataInfo->is_rm == -1) selected @endif>否</option>
                                                <option value="1" @if ($userGameDataInfo->is_rm == 1) selected @endif>是</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>通区编号：(通区RMB,通区元宝,通区RMB补发,红包币【英文逗号隔开】)
                                            </label>
                                            <input type="text" class="form-control" id="area_code" value="{{ $userGameDataInfo->area_code }}">
                                        </div>
                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>兑换平台：
                                            </label>
                                            <select class="form-control" id="dh_plat_id">
                                                <option value="0" @if ($userGameDataInfo->dh_plat_id == 0) selected @endif>请选择平台</option>
                                                @foreach($dhPlat as $item)
                                                    <option value="{{$item->id}}" @if ($userGameDataInfo->dh_plat_id == $item->id) selected @endif >{{$item->title}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>版本比例：</label>
                                            <select class="form-control" id="is_bilitype">
                                                <option value="0" @if ($userGameDataInfo->is_bilitype == 0) selected @endif>请选择</option>
                                                <option value="1" @if ($userGameDataInfo->is_bilitype == 1) selected @endif>百倍比例</option>
                                                <option value="2" @if ($userGameDataInfo->is_bilitype == 2) selected @endif>千倍比例</option>
                                                <option value="3" @if ($userGameDataInfo->is_bilitype == 3) selected @endif>精品推荐</option>
                                                <option value="4" @if ($userGameDataInfo->is_bilitype == 4) selected @endif>红包版本</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>是否手游：
                                            </label>
                                            <select class="form-control" id="is_mobile">
                                                <option value="0" @if ($userGameDataInfo->is_mobile == 0) selected @endif>请选择</option>
                                                <option value="1" @if ($userGameDataInfo->is_mobile == 1) selected @endif>是</option>
                                                <option value="2" @if ($userGameDataInfo->is_mobile == 2) selected @endif>否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-5" >
                                        <div class="form-group">
                                            <label>攻沙专区：
                                            </label>
                                            <select class="form-control" id="is_gs">
                                                <option value="0" @if ($userGameDataInfo->is_gs == 0) selected @endif>请选择</option>
                                                <option value="1" @if ($userGameDataInfo->is_gs == 1) selected @endif>是</option>
                                                <option value="2" @if ($userGameDataInfo->is_gs == 2) selected @endif>否</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-lg-5" >
                                        <div class="form-group">
                                            <label>是否抽奖：
                                            </label>
                                            <select class="form-control" id="is_draw">
                                                <option value="0" @if ($userGameDataInfo->is_draw == 0) selected @endif>请选择</option>
                                                <option value="1" @if ($userGameDataInfo->is_draw == 1) selected @endif>是</option>
                                                <option value="2" @if ($userGameDataInfo->is_draw == 2) selected @endif>否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-5" style="display: none;">
                                        <div class="form-group">
                                            <label>是否兑换乐游币：</label>
                                            <select class="form-control" id="is_lyb">
                                                <option value="0" @if ($userGameDataInfo->is_lyb == 0) selected @endif>请选择</option>
                                                <option value="1" @if ($userGameDataInfo->is_lyb == 1) selected @endif>是</option>
                                                <option value="2" @if ($userGameDataInfo->is_lyb == 2) selected @endif>否</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>版本状态：</label>
                                            <select class="form-control" id="is_tops">
                                                <option value="0" @if ($userGameDataInfo->is_tops == 0) selected @endif>即将下线</option>
                                                <option value="1" @if ($userGameDataInfo->is_tops == 1) selected @endif>火爆</option>
                                                <option value="2" @if ($userGameDataInfo->is_tops == 2) selected @endif>今日新上</option>
                                                <option value="3" @if ($userGameDataInfo->is_tops == 3) selected @endif>即将上线</option>
                                                <option value="4" @if ($userGameDataInfo->is_tops == 4) selected @endif>人气一般</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>技术人员选项：</label>
                                            <select class="form-control" id="technician" name="technician">
                                                <option value="1号技术" @if ($userGameDataInfo->technician == '1号技术') selected @endif>1号技术</option>
                                                <option value="2号技术" @if ($userGameDataInfo->technician == '2号技术') selected @endif>2号技术</option>
                                                <option value="3号技术" @if ($userGameDataInfo->technician == '3号技术') selected @endif>3号技术</option>
                                                <option value="4号技术" @if ($userGameDataInfo->technician == '4号技术') selected @endif>4号技术</option>
                                                <option value="5号技术" @if ($userGameDataInfo->technician == '5号技术') selected @endif>5号技术</option>
                                                <option value="6号技术" @if ($userGameDataInfo->technician == '6号技术') selected @endif>6号技术</option>
                                                <option value="7号技术" @if ($userGameDataInfo->technician == '7号技术') selected @endif>7号技术</option>
                                                <option value="8号技术" @if ($userGameDataInfo->technician == '8号技术') selected @endif>8号技术</option>
                                                <option value="9号技术" @if ($userGameDataInfo->technician == '9号技术') selected @endif>9号技术</option>
                                                <option value="10号技术" @if ($userGameDataInfo->technician == '10号技术') selected @endif>10号技术</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-lg-10 layui-form">
                                        <div class="form-group">
                                            <label>自定义链接：(格式：【站点[此处为英文逗号]链接】，一行一个，如：l3y.info,http://www.baidu.com)
                                            </label>
                                            <textarea id="extend_url" rows="5" style="width: 100%; border: 1px solid #ccc; border-radius: 4px; padding: 4px;">{{$userGameDataInfo->url_json}}</textarea>
                                        </div>
                                    </div>

                                    <div class="col-lg-10 layui-form">
                                        <div class="form-group">
                                            <label>关联标签：</label>
                                            @foreach($tags as $item)
                                                <input type="checkbox" class="game-tag-item" name="game-tag" data-id="{{$item->id}}" title="{{$item->tag_name}}" @if (in_array($item->id, $gameTags)) checked @endif>
                                            @endforeach
                                        </div>
                                    </div>

                                    <div class="col-lg-10">
                                        <div class="form-group">
                                            <div class="row">
                                                <div class="col-lg-10 col-md-7" style="margin-bottom: 10px">
                                                    <a href="javascript:void(0);" class="btn btn-primary" onclick="add_server()"> 添加服务器 </a>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="table-responsive">
                                            <table class="table table-sm table-hover text-center">
                                                <thead>
                                                <tr>
                                                    <th style="min-width:50px;">ID</th>
                                                    <th style="min-width:135px;">服务器名</th>
                                                    <th style="min-width:135px;">开服时间</th>
                                                    <th style="min-width:110px;">操作</th>
                                                </tr>
                                                </thead>
                                                @if(!empty($serverInfo))
                                                    <tbody>
                                                    @foreach($serverInfo as $serve)
                                                        <tr>
                                                            <td style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{$serve->id}}</td>
                                                            <td style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{$serve->server_name}}</td>
                                                            <td style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{$serve->open_server_time}}</td>
                                                            <td style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
                                                                <a href="javascript:void(0);" class="btn btn-primary btn-sm" onclick="edit_server({{$serve->id}},'{{$serve->server_name}}','{{$serve->open_server_time}}')">修改</a>
                                                                <a href="javascript:void(0);" class="btn btn-danger btn-sm" onclick="del_server({{$serve->id}})">删除</a>
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                @endif
                                            </table>
                                        </div>
                                    </div>

                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <button class="btn btn-primary" onclick="submit({{ $userGameDataInfo->id }})">提交</button>
                                        </div>
                                    </div>

                                </div>
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->


    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        function getTags() {
            let ids = []
            $.each($('.game-tag-item:checkbox:checked'),function(){
                ids.push(+$(this).attr('data-id'))
            });
            return ids
        }

        //默认选择类型
        $('#hour').val( $('#hour').data('hour') );
        $('#minute').val( $('#minute').data('minute') );

        let isLoading = false;

        //提交
        function submit(id) {

            let data = new Date();
            let year = data.getFullYear();              // 从 Date 对象以四位数字返回年份。
            let month = data.getMonth() + 1;            // 从 Date 对象返回月份 (0 ~ 11)。
            let strDate = data.getDate();               // 从 Date 对象返回一个月中的某一天 (1 ~ 31)。
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            let systemData = year + "-" + month + "-" + strDate;

            if (!$('#server_name').val()) {
                toast('服务器名称 不能为空');
                return false
            }
            if (!$('#server_ip').val()) {
                toast('服务器IP 不能为空。');
                return false
            }
            if (!$('#introduction').val()) {
                toast('版本介绍 不能为空。');
                return false
            }
            if( !$('#count').val()){
                toast('福利数量 不能为空。');
                return false
            }
            if (!$('#url').val()) {
                toast('游戏主页 不能为空。');
                return false
            }
            // 每天
            if ($('#is_every_day option:selected').val() == 2) {
                if (!$('#date').val()) {
                    toast('请选择 开机日期。');
                    return false
                }
                if ($('#date').val() < systemData) {
                    toast('开机日期 不能小于当前日期。');
                    return false
                }

                if (!$('#hour option:selected').val()) {
                    toast('开机时钟 不能为空。');
                    return false
                }

                if (!$('#minute option:selected').val()) {
                    toast('开机分钟 不能为空。');
                    return false
                }
            }

            if ($('#money').val() < 0) {
                toast('请输入领取福利。');
                return false
            }


            // 获取服务器信息
            let serverList = new Array();
            $(".server-name-item").each(function () {
                serverList.push($(this).val())
            })
            $('#kf_url').val($('#url').val())
            if (isLoading === false) {
                isLoading = true;

                axios.patch('{{ route('admin.games.update','').'/' }}' + id + '', {
                    server_name: $('#server_name').val(),
                    server_ip: $('#server_ip').val(),
                    open_time: $('#date').val() + ' ' + $('#hour').val() + ':' + $('#minute').val(),
                    stars: $('#stars').val(),
                    introduction: $('#introduction').val(),
                    login_down: $('#login_down').val(),
                    kf_url: $('#kf_url').val(),
                    count: $('#count').val(),
                    url: $('#url').val(),
                    server_list: serverList,
                    is_top: $('#is_top').val(),
                    image: $('#image-value').val(),
                    money: $('#money').val(),
                    is_all_day: $('#is_all_day option:selected').val(),
                    is_every_day: $('#is_every_day option:selected').val(),
                    is_tq: $('#is_tq option:selected').val(),
                    is_rm: $('#is_rm option:selected').val(),
                    is_gs: $('#is_gs option:selected').val(),
                    is_draw: $('#is_draw option:selected').val(),
                    is_mobile: $('#is_mobile option:selected').val(),
                    area_code: $('#area_code').val(),
                    dh_plat_id: $('#dh_plat_id option:selected').val(),
                    tags: getTags(),
                    is_bilitype: $('#is_bilitype option:selected').val(),
                    technician: $('#technician option:selected').val(),
                    extend_url: $('#extend_url').val(),
                    is_tops: $('#is_tops option:selected').val(),
                    is_lyb: $('#is_lyb option:selected').val(),
                    })
                    .then(function (response) {
                        isLoading = false;
                        toast(response.data.message);
                        if (response.data.success === 'true') {
                            setTimeout(() => {
                                window.location.href="javascript:history.go(-1)";
                            }, 2000)
                        }
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }

        function add_server() {
            let html = '<div class="modal fade" id="operation" tabindex="-1">' +
                '<div class="modal-dialog modal-dialog-centered">' +
                '<div class="modal-content">' +
                '<div class="modal-header">' +
                '<h5 class="modal-title">请输入服务器名</h5>' +
                '<button type="button" class="close" data-dismiss="modal">' +
                '<span aria-hidden="true">&times;</span>' +
                '</button>' +
                '</div>' +
                '<br><input type="text" class="form-control" id="server-name" value="" maxlength="50"><br>' +
                `
                <div class="form-row">

                <div class="col">
                    <div class="form-group">
                        <select class="form-control" id="server-hour">
                            <option value=""> 请选择时</option>
                            <option value="00">00</option>
                            <option value="07">07</option>
                            <option value="08">08</option>
                            <option value="09">09</option>
                            <option value="10">10</option>
                            <option value="11">11</option>
                            <option value="12">12</option>
                            <option value="13">13</option>
                            <option value="14">14</option>
                            <option value="15">15</option>
                            <option value="16">16</option>
                            <option value="17">17</option>
                            <option value="18">18</option>
                            <option value="19">19</option>
                            <option value="20">20</option>
                            <option value="21">21</option>
                            <option value="22">22</option>
                            <option value="23">23</option>
                        </select>
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <select class="form-control" id="server-minute">
                            <option value=""> 请选择分钟</option>
                            <option value="00">00</option>
                            <option value="05">05</option>
                            <option value="30">30</option>
                        </select>
                    </div>
                </div>
                </div>
                `+
                '<div class="modal-footer">' +
                '<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="submit_server()">确定</button>' +
                '<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';
            $('body').append(html);
            $('#operation').modal('show');
            $('#operation').on('hidden.bs.modal', function () {
                $('#operation').remove();
            });
        }

        function submit_server() {
            let name = $("#server-name").val()
            let date = `${$("#server-hour").val()}:${$("#server-minute").val()}`
            axios.post('{{ route('admin.games.createSer','') }}', {
                server_name: name,
                open_server_time: date,
                game_id: {{ $userGameDataInfo->id }},
            })
                .then(function (response) {
                    isLoading = false;
                    toast_tip2(response.data.message, window.location.href);
                })
                .catch(function (error) {
                    isLoading = false;
                    $.each(error.response.data.errors, function (index, object) {
                        toast(object[0]);
                        return false;
                    });
                })
        }

        function edit_server(id,value,date) {
            let hour = date.substr(0,2)
            let min = date.substr(3,2)
            let html = '<div class="modal fade" id="operation" tabindex="-1">' +
                '<div class="modal-dialog modal-dialog-centered">' +
                '<div class="modal-content">' +
                '<div class="modal-header">' +
                '<h5 class="modal-title">请输入服务器名</h5>' +
                '<button type="button" class="close" data-dismiss="modal">' +
                '<span aria-hidden="true">&times;</span>' +
                '</button>' +
                '</div>' +
                '<br><input type="text" class="form-control" id="edit-server-name" value="'+value+'" maxlength="50"><br>' +
                `
                <div class="form-row">

                <div class="col">
                    <div class="form-group">
                        <select class="form-control" id="server-hour">
                            <option value=""> 请选择时</option>
                            <option value="00">00</option>
                            <option value="07">07</option>
                            <option value="08">08</option>
                            <option value="09">09</option>
                            <option value="10">10</option>
                            <option value="11">11</option>
                            <option value="12">12</option>
                            <option value="13">13</option>
                            <option value="14">14</option>
                            <option value="15">15</option>
                            <option value="16">16</option>
                            <option value="17">17</option>
                            <option value="18">18</option>
                            <option value="19">19</option>
                            <option value="20">20</option>
                            <option value="21">21</option>
                            <option value="22">22</option>
                            <option value="23">23</option>
                        </select>
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <select class="form-control" id="server-minute">
                            <option value=""> 请选择分钟</option>
                            <option value="00">00</option>
                            <option value="05">05</option>
                            <option value="30">30</option>
                        </select>
                    </div>
                </div>
                </div>
                `+
                '<div class="modal-footer">' +
                '<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="submit_edit_server('+ id +')">确定</button>' +
                '<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';
            $('body').append(html);
            $('#operation').modal('show');
            $("#server-hour").find("option:contains('"+hour+"')").attr("selected",true);
            $("#server-minute").find("option:contains('"+min+"')").attr("selected",true);
            $('#operation').on('hidden.bs.modal', function () {
                $('#operation').remove();
            });
        }

        function submit_edit_server(id) {
            let name = $("#edit-server-name").val()
            let date = `${$("#server-hour").val()}:${$("#server-minute").val()}`
            axios.patch('{{ route('admin.games.editSer','') . '/'}}' + id + '', {
                server_name: name,
                open_server_time: date,
            })
                .then(function (response) {
                    isLoading = false;
                    toast_tip2(response.data.message, window.location.href);
                })
                .catch(function (error) {
                    isLoading = false;
                    $.each(error.response.data.errors, function (index, object) {
                        toast(object[0]);
                        return false;
                    });
                })
        }

        function del_server(id) {
            let html = '<div class="modal fade" id="operation" tabindex="-1">' +
                '<div class="modal-dialog modal-dialog-centered">' +
                '<div class="modal-content">' +
                '<div class="modal-header">' +
                '<h5 class="modal-title">提示</h5>' +
                '<button type="button" class="close" data-dismiss="modal">' +
                '<span aria-hidden="true">&times;</span>' +
                '</button>' +
                '</div>' +
                '<div class="modal-body">是否要继续操作？</div>' +
                '<div class="modal-footer">' +
                '<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="submit_del_server('+id+')">确定</button>' +
                '<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';
            $('body').append(html);
            $('#operation').modal('show');
            $('#operation').on('hidden.bs.modal', function () {
                $('#operation').remove();
            });
        }

        function submit_del_server(id) {
            axios.delete('{{ route('admin.games.delSer','') . '/'}}' + id + '', {

            })
                .then(function (response) {
                    isLoading = false;
                    toast_tip2(response.data.message, window.location.href);
                })
                .catch(function (error) {
                    isLoading = false;
                    $.each(error.response.data.errors, function (index, object) {
                        toast(object[0]);
                        return false;
                    });
                })
        }

        function upload_image() {
            var formData = new FormData();
            formData.append('file', $('#image')[0].files[0]);  //添加图片信息的参数
            $.ajax({
                url: "{{route('admin.games.uploadImg', '')}}",
                type: "post",
                dataType: "json",
                cache: false,
                data: formData,
                processData: false,// 不处理数据
                contentType: false, // 不设置内容类型
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function (data) {
                    if (data.status === 0) {
                        $('#show-image').attr('href', '/uploads/' + data.path)
                        $('#image-value').val(data.path)
                        $('#show-image').css('display', 'inline-block')
                        toast("添加成功");
                    }
                }
            })
        }
    </script>

    </body>

@endsection
